package cn.iocoder.yudao.module.dt.service.activitysumbit;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.dt.controller.admin.activitysumbit.vo.*;
import cn.iocoder.yudao.module.dt.dal.dataobject.activitysumbit.ActivitySumbitDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.dt.convert.activitysumbit.ActivitySumbitConvert;
import cn.iocoder.yudao.module.dt.dal.mysql.activitysumbit.ActivitySumbitMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.dt.enums.ErrorCodeConstants.*;

/**
 * 活动提交 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ActivitySumbitServiceImpl implements ActivitySumbitService {

    @Resource
    private ActivitySumbitMapper activitySumbitMapper;

    @Override
    public Integer createActivitySumbit(ActivitySumbitCreateReqVO createReqVO) {
        // 插入
        ActivitySumbitDO activitySumbit = ActivitySumbitConvert.INSTANCE.convert(createReqVO);
        activitySumbitMapper.insert(activitySumbit);
        // 返回
        return activitySumbit.getId();
    }

    @Override
    public void updateActivitySumbit(ActivitySumbitUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateActivitySumbitExists(updateReqVO.getId());
        // 更新
        ActivitySumbitDO updateObj = ActivitySumbitConvert.INSTANCE.convert(updateReqVO);
        activitySumbitMapper.updateById(updateObj);
    }

    @Override
    public void deleteActivitySumbit(Integer id) {
        // 校验存在
        this.validateActivitySumbitExists(id);
        // 删除
        activitySumbitMapper.deleteById(id);
    }

    private void validateActivitySumbitExists(Integer id) {
        if (activitySumbitMapper.selectById(id) == null) {
            throw exception(ACTIVITY_SUMBIT_NOT_EXISTS);
        }
    }

    @Override
    public ActivitySumbitDO getActivitySumbit(Integer id) {
        return activitySumbitMapper.selectById(id);
    }

    @Override
    public List<ActivitySumbitDO> getActivitySumbitList(Collection<Integer> ids) {
        return activitySumbitMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<ActivitySumbitDO> getActivitySumbitPage(ActivitySumbitPageReqVO pageReqVO) {
        return activitySumbitMapper.selectPage(pageReqVO);
    }

    @Override
    public List<ActivitySumbitDO> getActivitySumbitList(ActivitySumbitExportReqVO exportReqVO) {
        return activitySumbitMapper.selectList(exportReqVO);
    }

}
